<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<%@ include file="../base.jsp" %>
	<style>
	.content-wrapper{margin-left: 0px}
	</style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">
		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>视图管理<small>添加视图</small></h1>
				<ol class="breadcrumb">
					<li><a href="javascript:;"><i class="fa fa-dashboard"></i> 首页</a></li>
					<li class="active">添加视图</li>
				</ol>
			</section>
			<!-- Main content -->
			<section class="content">
				<div class="row">
					<div class="col-md-12">
			          <div class="box">
			            <div class="box-header with-border">
			              <h3 class="box-title">
			              	<div class="box-tools">
				              <a class="btn btn-primary" href="${url }analysis/view/toAdd">添加</a>
				            </div>
				           </h3>
			            </div>
			            <!-- /.box-header -->
			            <div class="box-body form-horizontal">
			            <!-- form start -->
							<form id="saveForm">
				              <div class="form-group">
				                 <label for="inputEmail3" class="col-sm-2 control-label">视图名称</label>
				                 <div class="col-sm-3">
				                   <input type="text" class="form-control" name="viewname">
				                 </div>
				               </div>
				               <div class="form-group">
				                 <label for="inputEmail3" class="col-sm-2 control-label">行数</label>
				                 <div class="col-sm-3">
				                   <input type="text" class="form-control" name="rows">
				                 </div>
				               </div>
				               <div class="form-group">
				                 <label for="inputEmail3" class="col-sm-2 control-label">列数</label>
				                 <div class="col-sm-3">
				                   <input type="text" class="form-control" name="column">
				                 </div>
				               </div>
				               <div class="box-footer">
					                <a class="btn btn-info save">添加</a>
					                <a class="btn btn-default cancel" href="${url }analysis/view/viewlist">取消</a>
					           </div>
					          </form>
			            </div>
			            <!-- /.box-body -->
			          </div>
				</div>
			</section>
		</div>
	</div>
</body>
<script src="${url }js/layer/layer.js"></script>
<script src="${url }bootstrap/js/jquery.validate.min.js"></script>
<script src="${url }bootstrap/js/messages_zh.js"></script>

<script type="text/javascript">
	$(function () {
		$('.save').on('click',function(){
			if($("#saveForm").valid()){
				$.ajax({
					type: "post", 
		            url: path+"/analysis/view/addView",
		            //url: "http://10.104.4.190:8000/custom/addView",
		            data:$('#saveForm').serialize(),
		            dataType: "json",
		            success: function(data){
		            	if(data){
		            		layer.alert('保存成功', {
		              		  closeBtn: 0
		              		}, function(){
			            		location.href = path+'/analysis/view/viewlist';
		              		});
		            	}else{
		            		layer.alert('保存失败！');
		            	}
		            }
				});
			}
		});
	});
	
	$("#saveForm").validate({
	    rules: {
	    	viewname:'required',
	    	rows: {
			 required: true,
			 range:[0,6]
			},
			column: {
			 required: true,
			 range:[0,6]
			}
	    }
	});
	</script>
	<style>
		.error{color:red;font-weight: 500;}
	</style>
</html>